home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User tools / Memory Monitor 1.0.3 / MemoryMonitor.vu < prev    next >
Encoding:
Text File  |  1994-06-15  |  12.0 KB  |  499 lines  |  [TEXT/MPS ]

  1. Libraries "MemoryMonitor.vulib";
  2.  
  3. #######################################################################################
  4. #    MemoryMonitor Example Script
  5. #
  6. # • What's this script do?
  7. #    This script demonstrates the Memory Monitor V.U. external tool.
  8. #
  9. # • Where will Memory Monitor run?
  10. #    If a target is assigned to the user within the V.U. document,
  11. #    then the script will expect Memory Monitor to be on the Target.
  12. #
  13. #    If the V.U. document has no target assigned,
  14. #    then the script will expect Memory Monitor to be on the Host.
  15. #
  16. #######################################################################################
  17. Script    MemoryMonitorExample()
  18. Begin
  19.         ###    These flags control the verbosity & beauty of printed output.
  20.         ###    All flags true yields more and formatted output.
  21.     global TraceToolCalls        := true;
  22.     global ReportSuccess        := true;
  23.     global FormattedOutput        := true;
  24.     
  25.         ###    Initialize Memory Monitor either on the Host, or the Target
  26.     OnTheTarget := match[ target ];
  27.     x := InitMemoryMonitor( OnTheTarget );
  28.  
  29.         ###    Demonstrate each available service
  30.     x := GetProcessInfo( 'Finder' ); 
  31.  
  32.         ###    Quit Memory Monitor
  33.      x := QuitMemoryMonitor();
  34.         
  35. end;
  36.  
  37. #######################################################################################
  38. Task CallEachService()
  39. Begin
  40.  
  41.         ###    Call each Memory Monitor service
  42.         ###    Exit with error code, if an error is encountered
  43.         
  44.     x := Demo_GetToolVersion();                     
  45.     
  46.     x := Demo_GetToolServices();                    
  47.     
  48.     x := Demo_ServiceSupported( 'GetToolVersion' ); 
  49.     
  50.     x := Demo_GetProcessInfo( 'Memory Monitor' );     
  51.  
  52.     x := Demo_GetAllProcesses();                     
  53.     
  54.     x := Demo_GetZoneMap( 'MultiFinderZone' );         
  55.     
  56.     x := Demo_GetZoneTotals( 'SystemZone' );         
  57.     
  58.     x := Demo_CheckZone( 'Memory Monitor' );         
  59.  
  60.     x := Demo_GetAboutThisMacintosh();                 
  61.     
  62.     x := Demo_ReadBytes();                             
  63.  
  64.     x := Demo_MacsbugCmd( "HT" );                    
  65.  
  66. end;
  67.  
  68. #######################################################################################
  69. Task Demo_GetToolVersion()
  70. Begin
  71.     
  72.     if global TraceToolCalls
  73.     begin
  74.         Println;
  75.         Println "———————————————————————————————————————    GetToolVersion";
  76.     end;
  77.     
  78.     x := MemoryMonitor( 'GetToolVersion' );
  79.     if x[1] = 0
  80.     begin
  81.         if global ReportSuccess
  82.         begin
  83.             Println x[2];
  84.         end;
  85.     end;
  86.     else
  87.     begin
  88.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  89.     end;
  90. end;
  91.  
  92. #######################################################################################
  93. Task Demo_GetToolServices()
  94. Begin
  95.     if global TraceToolCalls
  96.     begin
  97.         Println;
  98.         Println "———————————————————————————————————————    GetToolServices";
  99.     end;
  100.  
  101.     x := MemoryMonitor( 'GetToolServices' );
  102.     if x[1] = 0
  103.     begin
  104.         if global ReportSuccess
  105.             Println x[2];
  106.     end;
  107.     else
  108.     begin
  109.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  110.     end;
  111. end;
  112.  
  113. #######################################################################################
  114. Task Demo_ServiceSupported( SrvcName )
  115. Begin
  116.     if global TraceToolCalls
  117.     begin
  118.         Println;
  119.         Println "———————————————————————————————————————    ServiceSupported";
  120.     end;
  121.  
  122.     x := MemoryMonitor( 'ServiceSupported', SrvcName );
  123.     if x[1] = 0
  124.     begin
  125.         if global ReportSuccess
  126.             Println x[2];
  127.     end;
  128.     else
  129.     begin
  130.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  131.     end;
  132. end;
  133.  
  134. #######################################################################################
  135. Task Demo_GetAllProcesses()
  136. Begin
  137.     if global TraceToolCalls
  138.     begin
  139.         Println;
  140.         Println "———————————————————————————————————————    GetAllProcesses";
  141.     end;
  142.  
  143.     x := GetAllProcesses();
  144.     if x[1] = 0
  145.     begin
  146.         if global ReportSuccess
  147.         begin
  148.             if global FormattedOutput
  149.                 PrintProcessMap( x[2] );
  150.             else
  151.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  152.         end;
  153.     end;
  154.     else
  155.     begin
  156.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  157.     end;
  158. end;
  159.  
  160. #######################################################################################
  161. Task Demo_GetProcessInfo( ProcessName )
  162. Begin
  163.     if global TraceToolCalls
  164.     begin
  165.         Println;
  166.         Println "———————————————————————————————————————    GetProcessInfo";
  167.     end;
  168.  
  169.     x := GetProcessInfo( ProcessName );
  170.     if x[1] = 0
  171.     begin
  172.         if global ReportSuccess
  173.         begin
  174.             if global FormattedOutput
  175.                 PrintProcessInfo( x[2] );
  176.             else
  177.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  178.         end;
  179.     end;
  180.     else
  181.     begin
  182.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  183.     end;
  184. end;
  185.  
  186. #######################################################################################
  187. Task Demo_GetZoneMap( ZoneSelector )
  188. Begin
  189.     if global TraceToolCalls
  190.     begin
  191.         Println;
  192.         Println "———————————————————————————————————————    GetZoneMap : {ZoneSelector}";
  193.     end;
  194.  
  195.     x := GetZoneMap( ZoneSelector );
  196.     if x[1] = 0
  197.     begin
  198.         if global ReportSuccess
  199.         begin
  200.             if global FormattedOutput
  201.                 PrintZoneMap( x[2], ZoneSelector );
  202.             else
  203.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  204.         end;
  205.     end;
  206.     else
  207.     begin
  208.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  209.     end;
  210.     return x[1];
  211. end;
  212.  
  213. #######################################################################################
  214. Task Demo_GetZoneTotals( ZoneSelector )
  215. Begin
  216.     if global TraceToolCalls
  217.     begin
  218.         Println;
  219.         Println "———————————————————————————————————————    GetZoneTotals : {ZoneSelector}";
  220.     end;
  221.  
  222.     x := GetZoneTotals( ZoneSelector );
  223.     if x[1] = 0
  224.     begin
  225.         if global ReportSuccess
  226.         begin
  227.             if global FormattedOutput
  228.                 PrintZoneTotals( x[2], ZoneSelector );
  229.             else
  230.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  231.         end;
  232.     end;
  233.     else
  234.     begin
  235.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  236.     end;
  237.     return x[1];
  238. end;
  239.  
  240. #######################################################################################
  241. Task Demo_CheckZone( ZoneSelector )
  242. Begin
  243.     if global TraceToolCalls
  244.     begin
  245.         Println;
  246.         Println "———————————————————————————————————————    CheckZone : {ZoneSelector}";
  247.     end;
  248.  
  249.     x := CheckZone( ZoneSelector );
  250.     if    x[1] = 0 and TypeOf( x[2] ) = 'symbol'
  251.     begin
  252.         if global ReportSuccess
  253.         begin
  254.             if global FormattedOutput
  255.                 Println "Zone Ok - ", ZoneSelector;
  256.             else
  257.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  258.         end;        
  259.     end;
  260.     else
  261.     begin
  262.         if global FormattedOutput
  263.             Println "Zone Corrupt - ", ZoneSelector;
  264.         else
  265.             Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  266.     end;
  267.     return x[1];
  268. end;
  269.  
  270. #######################################################################################
  271. Task Demo_GetAboutThisMacintosh()
  272. Begin
  273.     if global TraceToolCalls
  274.     begin
  275.         Println;
  276.         Println "———————————————————————————————————————    GetAboutThisMacintosh";
  277.     end;
  278.  
  279.     x := GetAboutThisMacintosh();
  280.     if x[1] = 0
  281.     begin
  282.         if global ReportSuccess
  283.         begin
  284.             if global FormattedOutput
  285.                 PrintAboutThisMacintosh( x[2] );
  286.             else
  287.                 Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  288.         end;        
  289.     end;
  290.     else
  291.     begin
  292.         Println "DoGetAboutThisMacintosh";
  293.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  294.     end;
  295. end;
  296.  
  297. #######################################################################################
  298. Task Demo_ReadBytes()
  299. Begin
  300.     if global TraceToolCalls
  301.     begin
  302.         Println;
  303.         Println "———————————————————————————————————————    ReadBytes";
  304.     end;
  305.  
  306.         ###    Read the low global 'CurApName', 
  307.         ###    which contains the current application name
  308.     x := ReadBytes( { 0, 2320 }, 32 );
  309.     if x[1] = 0
  310.     begin
  311.         if global ReportSuccess
  312.         begin
  313.             if TypeOf( x[2] ) = 'list'
  314.             begin
  315.                     ### Assemble the bytes into a string and then print
  316.                 s := "";
  317.                 for i := 2 to x[2][1] + 1
  318.                     s := s + CodeToCharacter( x[2][i] );
  319.                 Println "Application Name ( CurApName ) = '", s, "'";
  320.             end;
  321.         end;        
  322.     end;
  323.     else
  324.     begin
  325.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  326.     end;
  327. end;
  328.  
  329. #######################################################################################
  330. Task Demo_MacsbugCmd( CmdLine )
  331. Begin
  332.     if global TraceToolCalls
  333.     begin
  334.         Println;
  335.         Println "———————————————————————————————————————    MacsbugCmd";
  336.     end;
  337.     
  338.     x := MacsbugCmd( CmdLine );
  339.     if x[1] = 0
  340.     begin
  341.         if global ReportSuccess
  342.         begin
  343.             Println "MacsbugCmd : '", CmdLine, "'";
  344.             Println "Result     : ", x[2];
  345.         end;
  346.     end;
  347.     else
  348.     begin
  349.         Println "MacsbugCmd : '", CmdLine, "'  Result : ", x[2];
  350.         Println x[1], "  ", x[2], "  ", x[3], "  ", x[4];
  351.     end;
  352. end;
  353.  
  354. #######################################################################################
  355. Task PrintProcessMap( pMap )
  356. Begin
  357.     for each P in pMap
  358.     begin
  359.         PrintProcessInfo( P );    
  360.     end;            
  361. end;
  362.  
  363. #######################################################################################
  364. Task PrintProcessInfo( P )
  365. Begin
  366.     Println;
  367.     Println "Name        - ", P[1];
  368.     Println "Type        - ", P[2];
  369.     Println "Signature   - ", P[3];
  370.     Println "Location    - ", RightJustify( P[4], 12 );
  371.     Println "Size        - ", RightJustify( P[5], 12 );
  372.     Println "Free Memory - ", RightJustify( P[6], 12 );
  373.     Println "Path Name   - ", P[7];
  374. end;
  375.  
  376. #######################################################################################
  377. Task PrintZoneMap( pMap, pZoneID, Label := "", Indent := "" )
  378. Begin
  379.     if Label = ""
  380.     begin
  381.         Println; 
  382.         Println "Zone                       First         Last          Size in";
  383.         Println "Specifier                  Address       Address       Bytes";
  384.         Println "---------                  -------       -------       -------";
  385.  
  386.         if TypeOf( pZoneID ) = 'list'
  387.             For each i in pZoneID
  388.             begin
  389.                 if TypeOf( i ) = 'integer'
  390.                 begin
  391.                     i := NumToStr( i );
  392.                 end;
  393.                 
  394.                 if Card Label > 0
  395.                     Label := Label + ", " + i;
  396.                 else
  397.                     Label := i;
  398.             end;
  399.         else
  400.         begin
  401.             Label := pZoneID;
  402.         end;
  403.     end;
  404.     
  405.     Println LeftJustify( Label, 20 ), 
  406.             Indent,
  407.             RightJustify( pMap[1], 14 ), 
  408.             RightJustify( pMap[2], 14 ), 
  409.             RightJustify( pMap[3], 14 );
  410.  
  411.     if TypeOf( pMap[4] ) = 'list'
  412.     begin
  413.         Index := 1;
  414.         for each Z in pMap[4]
  415.         begin
  416.             PrintZoneMap( Z, pZoneID, Label + "," + RightJustify( NumToStr( Index ), 2), Indent + "   " );
  417.             Index := Index + 1;
  418.         end;            
  419.     end;
  420. end;
  421.  
  422. #######################################################################################
  423. Task PrintZoneTotals( T, ZoneID := "" )
  424. Begin
  425.     Println "Zone Totals for : ", ZoneID;
  426.     Println "                        Blocks       Bytes";
  427.     Println "                        ------       -----";
  428.     Println "Free                  - ", RightJustify( NumToStr( T[1][1] ), 7 ), ", ", RightJustify( T[1][2], 11 );
  429.     Println "NonRelocatable        - ", RightJustify( NumToStr( T[2][1] ), 7 ), ", ", RightJustify( T[2][2], 11 );
  430.     Println "Relocatable           - ", RightJustify( NumToStr( T[3][1] ), 7 ), ", ", RightJustify( T[3][2], 11 );
  431.     Println "  Locked              - ", RightJustify( NumToStr( T[4][1] ), 7 ), ", ", RightJustify( T[4][2], 11 );
  432.     Println "  Purgable & Unlocked - ", RightJustify( NumToStr( T[5][1] ), 7 ), ", ", RightJustify( T[5][2], 11 );
  433.     Println "Total                 - ", RightJustify( NumToStr( T[6][1] ), 7 ), ", ", RightJustify( T[6][2], 11 );
  434. end;
  435.  
  436. #######################################################################################
  437. Task PrintAboutThisMacintosh( pAbout )
  438. Begin
  439.     Println "Built-in Memory      - ", RightJustify( pAbout[1], 10 ), "K";
  440.     Println "Total Memory         - ", RightJustify( pAbout[2], 10 ), "K";
  441.     Println "Largest Unused block - ", RightJustify( pAbout[3], 10 ), "K";
  442.     if (not IsUndefined( pAbout[4] )) and Card pAbout[4] > 1
  443.     begin
  444.         For each appInfo in pAbout[4]
  445.         begin
  446.             Println "  ", LeftJustify( appInfo[1], 32 ), " - ", RightJustify( appInfo[2], 10 ), "K";
  447.         end;
  448.     end;
  449. end;
  450.  
  451. #######################################################################################
  452. Task RightJustify( TStr, FieldWidth )
  453. begin
  454.     PadStr := "";
  455.     L := Card TStr;
  456.     if L < FieldWidth
  457.     begin
  458.         PadLength := FieldWidth - L;
  459.         L := (PadLength - Card PadStr) / 8;
  460.         for i := 1 to L 
  461.             PadStr := PadStr + "        ";
  462.  
  463.         If PadLength - Card PadStr >= 4
  464.             PadStr := PadStr + "    ";
  465.  
  466.         If PadLength - Card PadStr >= 2
  467.             PadStr := PadStr + "  ";
  468.  
  469.         If PadLength - Card PadStr >= 1
  470.             PadStr := PadStr + " ";
  471.     end;
  472.     return PadStr + TStr;
  473. end;
  474.  
  475. #######################################################################################
  476. Task LeftJustify( TStr, FieldWidth )
  477. begin
  478.     PadStr := "";
  479.     L := Card TStr;
  480.     if L < FieldWidth
  481.     begin
  482.         PadLength := FieldWidth - L;
  483.         L := (PadLength - Card PadStr) / 8;
  484.         for i := 1 to L 
  485.             PadStr := PadStr + "        ";
  486.  
  487.         If PadLength - Card PadStr >= 4
  488.             PadStr := PadStr + "    ";
  489.  
  490.         If PadLength - Card PadStr >= 2
  491.             PadStr := PadStr + "  ";
  492.  
  493.         If PadLength - Card PadStr >= 1
  494.             PadStr := PadStr + " ";
  495.     end;
  496.     return TStr + PadStr;
  497. end;
  498.  
  499.